package com.leetcode.August;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description: 228. 汇总区间
 * @Author: Mr.Fxy
 * @CreateTime: 2024-08-25 11:11
 */
public class LC228汇总区间 {
    public List<String> summaryRanges(int[] nums) {
        int n=nums.length;
        ArrayList<String> ans = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            int cur=nums[i];
            StringBuffer sb = new StringBuffer();
            sb.append(cur);
            while (i<n-1&&nums[i+1]==nums[i]+1)i++;
            if (nums[i]!=cur){
                sb.append("->").append(nums[i]);
            }
            ans.add(sb.toString());
        }
        return ans;
    }
}
